<?php


namespace App\Logic\User;


use App\Achieve\User;
use App\Logic\AbstractLogic;
use App\Rpc\UserLoginServiceInterface;
use HyperfExt\Jwt\JwtFactory;

class UserLoginLogic extends AbstractLogic
{
    /**
     * @var JwtFactory
     */
    protected $jwt;

    public $phone;

    public $code;

    public $from;

    public function rules(): array
    {
        return [
            "phone" => "required",
            "code" => "required",
        ];
    }

    public function attributes(): array
    {
        return [
            "phone"=> "手机号",
            "code"=> "验证码",
        ];
    }


    public function login()
    {
        $result = make(UserLoginServiceInterface::class)->loginWithPhoneCode($this->phone,$this->code);

        $jwt = $this->container->get(JwtFactory::class)->make();

        $token = $jwt->fromSubject(new User($result["user_id"],$result));

        return $token;
    }
}